<#include "../public/header.html">
<script type="text/javascript" src="public/ueditor/ueditor.config.js"></script>  
<script type="text/javascript" src="public/ueditor/ueditor.all.js"></script> 
<script type="text/javascript" src="public/js/ajaxUploadFile.js"></script>
<input type="hidden" name="id" value="${(po.id)!}" id="poid">
   <style>
   			textarea {
				display: block;
			}

   </style>
        <div id="tb" style="padding:5px 5px; border-bottom: dashed #d2d2d2 1px;margin-bottom: 5px;">
            文章类型: <input class="easyui-combobox" style="width:110px" name="student_sex" id="student_sex" value="${(po.student_sex!)!}" data-options="url:'admin/terms/getTermsToSelect',method:'get',valueField:'term_id',textField:'name'">
           	 文章名称: <input class="easyui-textbox" style="width:110px" id="name">
            <a href="javascript://" class="easyui-linkbutton" iconCls="icon-search" onclick="search_but()">搜索</a>
        </div>
        <table id="list" class="easyui-datagrid" title="文章列表" style="width:100%;height:100%"
               sortName="id"
               sortOrder="asc"
               rownumbers="true"
               pagination="true"
               pagesize="50"
               singleSelect="true"
               data-options="url:'admin/posts/listJson',toolbar:toolbar">
            <thead>
            <tr>
                <th field="id" width="100" sortable="true">文章ID</th>
                <th field="post_title" width="200" sortable="true">标题</th>
                <th field="post_zuozhe" width="200" sortable="true">作者</th>
                <th field="post_modified" width="200" sortable="true">日期</th>
                <th field="post_source" width="200" sortable="true">来源</th>
            </tr>
            </thead>
        </table>
        
        <div id="editdlg"></div>

    <script type="text/javascript">
        var id ;
        $(function(){
            $("#tb").prependTo(".datagrid-toolbar");
        })
        
        var toolbar = [{
            id:40101,
            disabled:"${((permission_button.p40101!) == 'true')? string('','true')}",
            text:'添加',
            iconCls:'icon-add',
            handler:function(){
				//$("#editdlg").css("display", "block");
                $("#editdlg").dialog({
                    title:"添加",
                    iconCls: 'icon-edit',
                    width: 700,
                    height: 600,
                    href:"admin/posts/postadd",
                    closed: false,
                    cache: false,        
                    onLoad:function() {
                        $.messager.progress('close');
                    },
                    buttons: [{
                        text: '取消',
                        iconCls:'icon-cancel',
                        handler: function () {
                            $('#ff').form('clear');
                            $("#editdlg").dialog("close");
                        }
                    },{
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $('#ff').form('submit',{
                                url:"admin/posts/postsave",
                                dataType:"json",
                                onSubmit:function(){
                                    
                                },
                                success:function(data){
                                    var data = eval('(' + data + ')');  // change the JSON string to javascript object

                                    alert(data.msg);
                                    $("#editdlg").dialog("close");
                                    $("#list").datagrid("reload");
                                }
                            });
                        }
                    }]
                });
            }
        },{
            id:40102,
            disabled:"${((permission_button.p40102!) == 'true')? string('','true')}",
            text:'编缉',
            iconCls:'icon-edit',
            handler:function(){
                var note =  $("#list").datagrid("getSelected");
                if(note == null){
                    $.messager.show({
                        title:'提醒',
                        msg:'请选择要编缉的行',
                        showType:'fade',
                        style:{
                            right:'',
                            bottom:''
                        }
                    });
                    return;
                }

                $.messager.progress({
                    text:'数据加载中....',
                    interval:100
                });

               $("#editdlg").dialog({
                   title:"编缉",
                   iconCls: 'icon-edit',
                   width: 700,
                   height: 600,
                   closed: false,
                   cache: false,
                   modal: true,
                   href:"admin/posts/postadd?id="+note.id,
                   onLoad:function() {
                       $.messager.progress('close');
                   },
                   buttons: [{
                       text: '取消',
                       iconCls:'icon-cancel',
                       handler: function () {
                           $('#ff').form('clear');
                           $("#editdlg").dialog("close");
                       }
                   },{
                       text: '保存',
                       iconCls: 'icon-ok',
                       handler: function () {
                           $('#ff').form('submit',{
                               url:"admin/posts/postsave",
                               onSubmit:function(){
                                   return $(this).form('enableValidation').form('validate');
                               },
                               success:function(data){
                                   var data = eval('(' + data + ')');  // change the JSON string to javascript object
                                   $.messager.alert('提示',data.msg);
                                   $("#editdlg").dialog("close");
                                   $("#list").datagrid("reload");
                               }
                           });
                       }
                   }]
               });
            }
        },'-',{
            id:40103,
            disabled:"${((permission_button.p40103!) == 'true')? string('','true')}",
            text:'删除',
            iconCls:'icon-delete',
            handler:function(){
                var note =  $("#list").datagrid("getSelected");
                if(note == null){
                    $.messager.show({
                        title:'提醒',
                        msg:'请选择行',
                        showType:'fade',
                        style:{
                            right:'',
                            bottom:''
                        }
                    });
                    return;
                }

                $.messager.confirm("警告","确定要删除吗？删除后一些历史数据可能会被影响，请确认！",function(r){
                    if(r){
                        $.ajax({
                            type:"POST",
                            url:"admin/posts/delete",
                            data:{id:note.id},
                            dataType:"json",
                            success:function(data){
                                $.messager.alert("提示",data.msg);
                                if(data.success == 1){
                                    $("#editdlg").dialog("close");
                                    $("#list").datagrid("reload");

                                }

                            }
                        });
                    }
                });
            }
        }];

        function search_but(){
           $("#list").datagrid("reload",{type:$("#type").combobox("getValue"),name:$("#name").val()});
        }
    </script>
    <#include "../public/footer.html">